package cn.z2huo.demo.multidatasource.mybatis.service.impl;

import cn.z2huo.demo.mapper.user.UserMapper;
import cn.z2huo.demo.model.dataobject.user.UserDO;
import cn.z2huo.demo.multidatasource.mybatis.constant.DataSourceConstant;
import cn.z2huo.demo.multidatasource.mybatis.dao.UserDAO;
import com.baomidou.dynamic.datasource.annotation.DS;
import jakarta.annotation.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *
 * @author z2huo
 */
@Service
public class UserServiceImpl {

    @Autowired
    private UserDAO userDAO;

    @Autowired
    private UserMapper userMapper;

    @Nullable
    @DS(DataSourceConstant.SLAVE_1)
    @Transactional
    public UserDO getUserByUserCode(String userCode) {
        return userDAO.getUserByUserCode(userCode);
    }

    @DS(DataSourceConstant.MASTER)
    @Transactional
    public void insert(UserDO userDO) {
        userMapper.insertSelective(userDO);
    }

}
